<template>
    <div class='input-card-button' :style="styles" >
        <input-card :id="idnew" ref="inputCards" class='inputs' :fontSize="fontSize" :isreadonly="isreadonlys" :isRequired="isRequired" :extype="extype" :exkey="exkeys"  :data="data"  @input="changeData" :expost="expost" :appid="appid" :index="index"></input-card>
        <div :class='className' v-if="isreadonlys!='Y'">
            <read-card :id="highShotId" @input="changeData" v-if="isLT" style="margin-left:10px"></read-card>
            <read-cardjy :id="highShotId" @input="changeData"  v-if="isJY" style="margin-left:10px"></read-cardjy>
            <read-cardxzx :id="highShotId" @input="changeData"  v-if="isXzx" style="margin-left:10px"></read-cardxzx>
            <read-cardjl :id="highShotId" @input="changeData"  v-if="isJl" style="margin-left:10px"></read-cardjl>
            <read-cardlt :id="highShotId" @input="changeData"  v-if="isLtGF" style="margin-left:10px"></read-cardlt>
            <read-cardhs :id="highShotId" @input="changeData"  v-if="ishs"  style="margin-left:10px"></read-cardhs>
            <read-card-ocrlt :id="highShotId" @input="changeData"  v-if="ocr=='lt'" style="margin-left:10px"></read-card-ocrlt>
            <read-cardhx :id="highShotId" @input="changeData"  v-if="ishx"></read-cardhx>
        </div>
    </div>
                            
</template>
<script>
import InputCard  from './input-card'
import ReadCard  from '../highShot/ReadCard'
import ReadCardjy  from '../highShot/ReadCardjy'
import ReadCardxzx  from '../highShot/ReadCardxzx'
import ReadCardjl  from '../highShot/ReadCardjl'
import ReadCardlt  from '../highShot/ReadCardlt'
import ReadCardOcrlt  from '../highShot/ReadCardOcrlt'
import ReadCardhx  from '../highShot/ReadCardhx'
import ReadCardhs  from '../highShot/ReadCardhs'
export default {
    props:['id','value','styles','disableds','data','isreadonly','index','isRequired','isPassword','extype','exkey','expost','appid','index','fontSize'],
    name: "input-card-button",
    components:{
        InputCard,
        ReadCard,
        ReadCardjy,
        ReadCardxzx,
        ReadCardjl,
        ReadCardlt,
        ReadCardOcrlt,
        ReadCardhx,
        
        ReadCardhs
    },
    data(){
        return{
            idnew:"",
            highShotId:"",
            exkeys:"",
            isLT:false,
            isJY:false,
            isXzx:false,
            isLtGF:false,
            isJl:false,//精伦读卡器
            ishx:false,//华旭
            ishs:false,//华视 100U
            ocr:false,
            className:"buttons",
            isreadonlys:""
        }
    },
    mounted(){
            
            try{
                this.$refs.inputCards.$parent.$parent.$children[0].$el.style.fontSize=this.fontSize
            }catch(e){}
        },
    created(){
        let index=this.id.lastIndexOf("|");
        this.idnew=this.id.substring(index+1).replace("id:","");
        this.highShotId=this.id.substring(0,index);
        let isOk=false;
       // alert(this.idnew+"=="+this.index)
     //  alert(this.exkey.type)
        try{
            if(this.exkey.type){
                if(this.exkey.type=="jy"){
                    this.isJY=true;
                    isOk=true;
                    this.exkeys=this.exkey.val
                }else if(this.exkey.type=='xzx'){
                    this.isXzx=true;
                    isOk=true;
                    this.exkeys=this.exkey.val
                }else if(this.exkey.type=='jl'){
                    this.isJl=true;
                    isOk=true;
                    this.exkeys=this.exkey.val;
                }else if(this.exkey.type=='lt'){
                    this.isLtGF=true;
                    isOk=true;
                    this.exkeys=this.exkey.val;
                }else if(this.exkey.type=='hx'){
                    this.ishx=true;
                    isOk=true;
                    this.exkeys=this.exkey.val
                }else if(this.exkey.type=='hs'){
                    this.ishs=true;
                    isOk=true;
                    this.exkeys=this.exkey.val
                }else{
                    this.isLT=true;
                }
            }
        }catch(e){

        }
        try{
            if(this.exkey.ocr){
                this.ocr=this.exkey.ocr;
                this.className="buttons2"
            }
        }catch(e){}
        if(!isOk){
            this.exkeys=this.exkey;
            this.isLT=true;
        }

        /*try{
              if(this.exkeys.readonlys){
                    
                  for(let i=0;i<this.exkeys.readonlys.length;i++){
                      let id=this.exkeys.readonlys[i].id;
                      let opr=this.exkeys.readonlys[i].opr;
                      let vals=this.exkeys.readonlys[i].val;
                      let val_=this.data[ids[0]][id];
                      if(opr=="等于"&&vals==val_){
                          this.isreadonlys="Y";
                      }
                      if(opr=="不等于"&&vals!=val_){
                          this.isreadonlys="Y";
                      }

                  }
              }
          }catch(e){}*/

          try{
                if(this.exkey.readonlys){
                    let isReadonly_="Y"
                    let idss=this.idnew.split(".");
                    for(let i=0;i<this.exkey.readonlys.length;i++){
                        let ids=this.exkey.readonlys[i].id.split(".");
                        
                        let opr=this.exkey.readonlys[i].opr;
                        let vals=this.exkey.readonlys[i].val;
                        let val_="";
                        if(ids[0]=="本身"){
                            val_=this.currentValue;
                        }else{
                            if(ids.length==2)
                                val_=this.data[ids[0]][ids[1]];
                            else
                                val_=this.data[idss[0]][ids[0]]
                        }
                        
                        if(opr=="等于"&&vals!=val_){
                            //this.isreadonlys="Y";
                            isReadonly_="N"
                        }
                        if(opr=="不等于"&&vals==val_){
                            //this.isreadonlys="Y";
                            isReadonly_="N"
                        }

                    }
                    this.isreadonlys=isReadonly_;
                }
            }catch(e){}

    },
    methods:{
        changeData(data){
           
            if(this.index||this.index=='0'){
                let item=JSON.parse(data);
                item.index=this.index;
                data=JSON.stringify(item)
            }
            this.$emit("input",data);
        }
    }
}
</script>
<style scoped>
    .input-card-button{
        display:flex;
        flex-direction: row;
    }
    .inputs{
        flex:1;
    }
    .buttons{
        width:80px;
        display:flex;
        flex-direction: row;
    }
    .buttons2{
        width:160px;
        display:flex;
        flex-direction: row;
    }
</style>